package com.eva.job;

import com.alibaba.fastjson.JSON;
import com.eva.core.job.BaseJob;
import com.eva.core.job.JobContext;
import com.eva.core.job.JobParam;
import com.eva.dao.system.model.SystemPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 带分发的定时任务
 * @author Caesar Liu
 * @date 2022-02-24 11:25
 */
@Slf4j
@Component
public class TestJob2 extends BaseJob {

    @Override
    public JobContext execute(JobParam param) {
        JobContext jobContext = new JobContext();
        List<SystemPermission> permissions = param.getRuntimeData(SystemPermission.class);
        StringBuilder context = new StringBuilder();
        for (SystemPermission permission : permissions) {
            context.append(JSON.toJSONString(permission));
            context.append("\n");
        }
        jobContext.setHandleSuccessSize(permissions.size());
        jobContext.setHandleTotalSize(permissions.size());
        jobContext.setContext(context.toString());
        return jobContext;
    }
}
